﻿namespace DataCapture.Helper;
using Redbus.Interfaces;
using Redbus;
using Redbus.Events;

/// <summary>
/// 简单易用的内存消息总线库(内部数据通讯)
/// </summary>
internal class EventBusHelper
{
    private static EventBusHelper _instance;
    private static readonly object Padlock = new object();
    private readonly IEventBus eventBus;

    private EventBusHelper()
    {
        eventBus = new EventBus();
    }

    public static EventBusHelper Instance
    {
        get
        {
            lock (Padlock)
            {
                return _instance ??= new EventBusHelper();
            }
        }
    }
    /// <summary>
    /// EventBus单例
    /// </summary>
    /// <returns></returns>
    public static IEventBus EventBus()
    {
        if (_instance == null)
        {
            return EventBusHelper.Instance.eventBus;
        }
        return _instance.eventBus;
    }
}
/// <summary>
/// 自定义事件
/// </summary>
/// <typeparam name="TPayload"></typeparam>
public class RWEventCommon<TPayload> : EventBase
{
    public readonly string EventKey;
    public TPayload Payload { get; protected set; }

    public RWEventCommon(string eventKey, TPayload payload)
    {
        EventKey = eventKey;
        Payload = payload;
    }
}